package org.netEase.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.netEase.dao.shangpingDao;
import org.netEase.dao.zhutiDao;
import org.netEase.dao.zhutizuDao;
import org.netEase.dao.impl.shangpingDaoImple;
import org.netEase.dao.impl.zhutiDaoImpl;
import org.netEase.dao.impl.zhutizuDaoImpl;
import org.netEase.entity.shangping;
import org.netEase.entity.zhuti;
import org.netEase.entity.zhutizu;
import org.netEase.util.pageBean;
@WebServlet(urlPatterns= {"/backstageManager/prlist.shtml"})
public class prlist extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String zid=request.getParameter("zid");
		String yid=request.getParameter("yid");
		 pageBean pageBean = new pageBean(); 
		 shangpingDao shangpingDao = new shangpingDaoImple();
		 int zi=0;
			if(zid!=null) {
				zi=Integer.parseInt(zid) ;
			}
			int yi=0;
			if(yid!=null) {
				yi=Integer.parseInt(yid) ;
			}
		 int condition= shangpingDao.getCount(zi,yi);
		 pageBean.setTotal(condition);
		 String pageStr = request.getParameter("p");
			if(pageStr != null){
				pageBean.setPageNo(Integer.parseInt(pageStr));
			}
			
		List<shangping> shangpings=shangpingDao.listGetByZid(pageBean.getPageNo(),pageBean.getSize(), zi, yi);
		
		request.setAttribute("zi", zi);
		request.setAttribute("yi", yi);
		request.setAttribute("shangpings", shangpings);
		request.setAttribute("pageBean", pageBean);
		zhutiDao zhutiDao = new zhutiDaoImpl();
		List<zhuti> list=zhutiDao.getlist();
		zhutizuDao zhutizuDao = new zhutizuDaoImpl();
		List<zhutizu> lists=zhutizuDao.getID(yi);
		request.setAttribute("list", list);
		request.setAttribute("lists", lists);
		request.getRequestDispatcher("/backstageManager/product-list.jsp").forward(request, response);
		
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}
}
